package com.zzxy.springSun.po;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

import java.nio.channels.Pipe;

/*1.instantiate bean对象实例化
2.populate properties 封装属性
3.如果Bean实现BeanNameAware 执行 setBeanName
4.如果Bean实现BeanFactoryAware 执行setBeanFactory ，获取Spring容器
5.如果存在类实现 BeanPostProcessor（后处理Bean） ，执行postProcessBeforeInitialization
6.如果Bean实现InitializingBean 执行 afterPropertiesSet
7.调用<bean init-method="init"> 指定初始化方法 init
8.如果存在类实现 BeanPostProcessor（处理Bean） ，执行postProcessAfterInitialization
        执行业务处理
9.如果Bean实现 DisposableBean 执行 destroy
10.调用<bean destroy-method="customerDestroy"> 指定销毁方法 customerDestroy*/
public class User implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        System.out.println("2. set username...");
        this.username = username;
    }
public User(){
        System.out.println("1.init instantiate");
}

    @Override
    public void setBeanName(String s) {
        System.out.println("3. bean neme aware: " + s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4. setBeanFactory: " + beanFactory);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6.afterProperties...");
    }
    public void myInit(){
        System.out.println("7. My init function...");
    }

    @Override
    public void destroy() throws Exception {
       System.out.println("9.destory...");
    }
    public void myDestory(){
        System.out.println("10.destory...");
    }
}
